/**
 * @param {number[]} nums1
 * @param {number[]} nums2
 * @return {number[]}
 */
var intersect = function (nums1, nums2) {
    let res = [];
    let map = {};
    if (nums1.length > nums2.length) {
        var lg = nums1;
        var sm = nums2;
    }
    else {
        lg = nums2;
        sm = nums1;
    }
    let n = lg.length;
    let m = sm.length;
    for (let i = 0; i < n; i++) {
        let temp1 = lg[i];
        if (!map.hasOwnProperty(temp1)) {
            map[temp1] = 1;
        } else {
            map[temp1]++;
        }
    }
    console.log(map);
    for (let j = 0; j < m; j++) {
        let temp2 = sm[j];
        if (map.hasOwnProperty(temp2) && map[temp2] !== 0) {
            res.push(temp2);
            map[temp2]--;
        }
    }
    console.log(res);
    return res;
};
intersect([1, 2], [2, 1]);